package com.bizuma.template;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.unitils.UnitilsJUnit4;
import org.unitils.inject.annotation.InjectIntoByType;
import org.unitils.inject.annotation.TestedObject;
import org.unitils.orm.jpa.annotation.JpaEntityManagerFactory;

import com.bizuma.template.domain.Address;
import com.bizuma.template.domain.Person;
import com.bizuma.template.provider.PersonProvider;
import com.bizuma.template.provider.impl.PersonProviderImpl;

@JpaEntityManagerFactory(persistenceUnit = "person_test", configFile = "test-persistence.xml")
public class PersonTestWithSpring extends UnitilsJUnit4 {

	private static Logger logger = Logger.getLogger(PersonTestWithSpring.class);

	@PersistenceContext
	@InjectIntoByType
	protected EntityManager em;

	@TestedObject
	PersonProvider personService;

	@Before
	public void setUp() throws Exception {
		this.personService = new PersonProviderImpl();
	}

	@After
	public void tearDown() throws Exception {
		this.personService = null;
	}

	@Test
	public void registerPerson() {
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		logger.debug("------------------------------");
		Address a1 = new Address("A Rd.", "", "Dallas", "TX", "75001");
		Person p1 = new Person("Brett", 'L', "Schuchert", a1);
		this.personService.registerPerson(p1);
	}
}
